package com.ruoyi.project.rate.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFPicture;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.rate.Constants;
import com.ruoyi.project.rate.Utils;
import com.ruoyi.project.rate.domain.Attach;
import com.ruoyi.project.rate.domain.Scene;
import com.ruoyi.project.rate.service.AttachService;
import com.ruoyi.project.rate.service.SceneService;
import com.ruoyi.project.system.config.service.IConfigService;
import com.ruoyi.project.system.dept.domain.Dept;
import com.ruoyi.project.system.role.service.IRoleService;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.service.IUserService;

@Controller
@RequestMapping("/rate/scene")
public class SceneController extends BaseController {
	@Autowired
	private SceneService sceneService;
	@Autowired
	private AttachService attachService;
	@Autowired
	private IRoleService roleService;
	@Autowired
    private IConfigService configService;
	@Autowired
	private IUserService userService;

	@RequestMapping("/scene")
	public String scene(Scene scene, ModelMap mmap) {
		String pageFlag = scene.getPageFlag();
		if (StringUtils.isBlank(pageFlag)) {
			throw new RuntimeException("请求参数错误, pageFlag is blank.");
		}
		
		List<Dept> deptList = Utils.level2DeptList();
		
		if (StringUtils.equalsAny(pageFlag,
				Constants.SCENE_STATUS_CHECK10,
				Constants.SCENE_STATUS_CHECK20)) {
			scene.setStatus(pageFlag);
		}
		if (Constants.PAGE_FLAG_QUERY.equals(pageFlag)) {
			scene.setDept(ShiroUtils.getSysDept());
			deptList.clear();
			deptList.add(ShiroUtils.getSysDept());
		}
		
		/**
		if (StringUtils.equals(Constants.SCENE_STATUS_CHECK30, pageFlag)) {
			Calendar c = Calendar.getInstance();
			c.setTime(new Date());
			c.add(Calendar.DAY_OF_MONTH, -1);
			scene.setDayId(new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()));
		}
		**/
		
		// scene.setMonthId(Utils.currentMonth());
		mmap.put("scene", scene);
		
		mmap.put("deptList", deptList);

		return "rate/sceneList";
	}

	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Scene scene) {
		String pageFlag = scene.getPageFlag();
		if (StringUtils.isBlank(pageFlag)) {
			throw new RuntimeException("请求参数错误, pageFlag is blank.");
		}
		
		if (Constants.PAGE_FLAG_SUBMIT.equals(pageFlag)) {
			// 创建页面只能看到自己的单子
			scene.setCreateUser(ShiroUtils.getSysUser());
		} else if (Constants.SCENE_STATUS_CHECK10.equals(pageFlag)) {
			scene.setFgldChecker(ShiroUtils.getSysUser());
		} else if (Constants.SCENE_STATUS_CHECK20.equals(pageFlag)) {
			// 监狱领导审核
		} else if (Constants.SCENE_STATUS_CHECK30.equals(pageFlag)) {
			// 政治处审核
		} else if (Constants.PAGE_FLAG_QUERY.equals(pageFlag)) {
			scene.setDept(ShiroUtils.getSysDept());
			scene.setStatus(Constants.SCENE_STATUS_APPROVED);
		}

		startPage();
		List<Scene> list = this.sceneService.findList(scene);
		
		this.setPicForScene(list);
		
		return getDataTable(list);
	}

	@RequestMapping("/add")
	public String add(Scene scene, ModelMap mmap) {
		/*
		 * ywzh/ynzh显示当日值班主任、应急分队人员
		 * tjd账号显示特警队员一、特警队员二
		 */
		String personNameFlag = "1";
		if (StringUtils.equalsIgnoreCase("tjd", ShiroUtils.getLoginName())) {
			personNameFlag = "2";
		}
		scene.setPersonNameFlag(personNameFlag);
		
		// 如果是从已有单子复制过来的，设置一些预置信息
		if (StringUtils.isNotBlank(scene.getId())) {
			Scene exists = this.sceneService.get(scene.getId());
			scene.setId(null);
			if (exists != null) {
				scene.setDayId(exists.getDayId());
				scene.setPerson1(exists.getPerson1());
				scene.setPerson2(exists.getPerson2());
				scene.setFgldChecker(exists.getFgldChecker());
			}
		}
		
		mmap.put("deptList", Utils.level2DeptList());
		mmap.put("scene", scene);
		
		mmap.put("fgldList", this.getFgldList());
				
		return "rate/sceneForm";
	}

	@RequestMapping("/edit")
	public String edit(Scene scene, ModelMap mmap) {
		Scene s = this.sceneService.get(scene);
		if (s == null) {
			throw new RuntimeException("找不到对应的数据！");
		}
		s.setPageFlag(scene.getPageFlag());
		s.setReserveStatus(scene.getReserveStatus());

		this.setPicForScene(s);
		
		mmap.put("scene", s);
		mmap.put("deptList", Utils.level2DeptList());
		
		mmap.put("fgldList", this.getFgldList());
		
		// 审核时需要展示审核区域
		String showCheckResult = "0";
		if (StringUtils.equalsAny(s.getPageFlag(),
				Constants.SCENE_STATUS_CHECK10,
				Constants.SCENE_STATUS_CHECK20)) {
			showCheckResult = "1";
		}
		mmap.put("showCheckResult", showCheckResult);
		
		return "rate/sceneForm";
	}

	@PostMapping("/save")
	@ResponseBody
	public AjaxResult save(Scene scene, @RequestParam Map<String, String> requestMap) {
		String pageFlag = scene.getPageFlag();
		if (StringUtils.isBlank(scene.getDayId())) {
			throw new RuntimeException("dayId is blank.");
		}
		if (!StringUtils.equalsAny(pageFlag, "ADD", "EDIT")) {
			throw new RuntimeException("error pageFlag.");
		}
		
		if (scene.getDept() == null || scene.getDept().getDeptId() == null || scene.getDept().getDeptId() == 0L) {
			throw new RuntimeException("please select dept.");
		}
		
		if (scene.getFgldChecker() == null
				|| scene.getFgldChecker().getUserId() == null
				|| scene.getFgldChecker().getUserId() <= 0L) {
			throw new RuntimeException("请选择对应的审核领导！");
		}
		
		// 如果所选领导是jyz角色，则直接设置为监狱长审核
		String status = Constants.SCENE_STATUS_CHECK10;
		Set<String> selectRoleKeys = this.roleService.selectRoleKeys(scene.getFgldChecker().getUserId());
		if (selectRoleKeys != null && (selectRoleKeys.contains("jyz") || selectRoleKeys.contains("JYZ"))) {
			status = Constants.SCENE_STATUS_CHECK20;
		}
		
		// 管理员编辑时仍旧保留原有的状态
		if (StringUtils.equals("1", scene.getReserveStatus()) && StringUtils.isNotBlank(scene.getId())) {
			Scene exist = this.sceneService.get(scene);
			String currentStatus = exist.getStatus();
			if (StringUtils.isNotBlank(currentStatus)) {
				status = currentStatus;
			}
		}
		
		scene.setMonthId(scene.getDayId().substring(0, 7));
		scene.setStatus(status);
		this.sceneService.saveScene(scene);

		return AjaxResult.success("保存成功！");
	}
	
	@RequestMapping("/check")
	public String check(Scene scene, ModelMap mmap) {
//		scene.setStatus(Constants.SCENE_STATUS_APPROVED);
		// scene.setMonthId(Utils.currentMonth());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DAY_OF_MONTH, -1);
		scene.setDayId(sdf.format(c.getTime()));
		mmap.put("scene", scene);

		return "rate/sceneCheckList";
	}

	@PostMapping("/checkList")
	@ResponseBody
	public TableDataInfo checkList(Scene scene) {
		scene.setStatus(Constants.SCENE_STATUS_APPROVED);
		List<Scene> list = this.sceneService.checkList(scene);
		
		List<User> userList = this.userService.selectUserList(new User());
		Map<String, User> userMap = new HashMap<>();
		for (User u : userList) {
			userMap.put(u.getUserId().toString(), u);
		}
		
		for (Scene s : list) {
			if (s.getCreateUser() != null || s.getCreateUser().getUserId() != null && !s.getCreateUser().getUserId().equals(0)) {
				User u = userMap.get(s.getCreateUser().getUserId().toString());
				if (u != null) {
					s.setCreateUser(u);
				}
			}
		}
		return getDataTable(list);
	}
	
	// 设置附件信息
	private void setPicForScene(Scene s) {
		Attach a = new Attach();
		a.setRelId(s.getId());
		List<Attach> attachList = this.attachService.findList(a);
		if (attachList == null) {
			attachList = new ArrayList<>();
		}
		s.setAttachList(attachList);
		if (attachList.size() > 0) {
			s.setAttach(attachList.get(0));
		}
	}
	private void setPicForScene(List<Scene> list) {
		// 设置附件信息
		for (Scene s : list) {
			this.setPicForScene(s);
		}
	}
	
	@RequestMapping("/export")
	@ResponseBody
	public AjaxResult export(Scene scene) {
		// 仅导出某一天审核通过的数据
		String dayId = scene.getDayId();
		scene = new Scene();
		scene.setDayId(dayId);
		if (StringUtils.isBlank(scene.getDayId())) {
			return AjaxResult.error("请选择日期");
		}
		// scene.setStatus(Constants.SCENE_STATUS_APPROVED);
//		scene.getExStatus().add(Constants.SCENE_STATUS_DRAFT);
//		scene.getExStatus().add(Constants.SCENE_STATUS_REJECTED);
		List<Scene> sceneList = this.sceneService.findList(scene);
		this.setPicForScene(sceneList);
		
		String[] ss = scene.getDayId().split("-");
		String year = ss[0];
		String month = ss[1];
		if (month.startsWith("0")) {
			month = month.substring(1);
		}
		String day = ss[2];
		if (day.startsWith("0")) {
			day = day.substring(1);
		}
		
		HSSFWorkbook wb = null;
		OutputStream out = null;
		String filename = "现场管理考核日通报（" + month + "月" + day + "日）" + ".xls";
		try {
			wb = new HSSFWorkbook();
			Sheet sheet;
			Row row;
			Cell cell;
			CellRangeAddress region;
			int sheetIndex = 0;
			int rowIndex = 0;
			int colIndex = 0;
			
			CellStyle songti20boldcenterwithoutborder = this.songti20BoldCenterWithoutBorder(wb);
			CellStyle songti14boldleftwithoutborder = this.songti14BoldLeftWithoutBorder(wb);
			CellStyle songti12boldcenterwithborder = this.songti12BoldCenterWithBorder(wb);
			CellStyle songti14centerwithborder = this.songti14CenterWithBorder(wb);
			CellStyle songti14leftwithborder = this.songti14LeftWithBorder(wb);
			
			// 汇总表 begin
			sheet = wb.createSheet();
			wb.setSheetName(sheetIndex++, "汇总表");
			rowIndex = 0;
			
			// 产生表头0 begin
			colIndex = 0;
			int totalSize = 7;
			row = sheet.createRow(rowIndex++);
			row.setHeight((short)(40 * 20));
			cell = row.createCell(colIndex++);
			cell.setCellValue("现场管理考核日通报统计表");
			cell.setCellStyle(songti20boldcenterwithoutborder);
			for (int i = 0; i < (totalSize - 1); i++) {
				cell = row.createCell(colIndex++);
				cell.setCellStyle(songti20boldcenterwithoutborder);
			}
			region = new CellRangeAddress(rowIndex-1, rowIndex-1, colIndex - totalSize, colIndex-1);
			sheet.addMergedRegion(region);
			// 产生表头0 end
			
			// 产生表头1 begin
			colIndex = 0;
			row = sheet.createRow(rowIndex++);
			row.setHeight((short)(38 * 20)); 
			cell = row.createCell(colIndex++);
			cell.setCellStyle(songti14boldleftwithoutborder);
			cell.setCellValue("日期："+year+"年"+month+"月"+day+"日");
			totalSize = 7;
			for (int i = 0; i < (totalSize - 1); i++) {
				cell = row.createCell(colIndex++);
				cell.setCellStyle(songti14boldleftwithoutborder);
			}
			region = new CellRangeAddress(rowIndex-1, rowIndex-1, colIndex - totalSize, colIndex-1);
			sheet.addMergedRegion(region);
			// 产生表头1 end
			
			// 产生表头2 begin
			colIndex = 0;
			row = sheet.createRow(rowIndex++);
			row.setHeight((short)(38 * 20));
			cell = row.createCell(colIndex++);
			cell.setCellValue("序号");
			cell.setCellStyle(songti12boldcenterwithborder);
			sheet.setColumnWidth(colIndex - 1, 7 * 256);
			cell = row.createCell(colIndex++);
			cell.setCellValue("考核单位");
			cell.setCellStyle(songti12boldcenterwithborder);
			sheet.setColumnWidth(colIndex - 1, 14 * 256);
			cell = row.createCell(colIndex++);
			cell.setCellValue("考核内容");
			cell.setCellStyle(songti12boldcenterwithborder);
			sheet.setColumnWidth(colIndex - 1, 45 * 256);
			cell = row.createCell(colIndex++);
			cell.setCellValue("截图");
			cell.setCellStyle(songti12boldcenterwithborder);
			sheet.setColumnWidth(colIndex - 1, 35 * 256);
//			cell = row.createCell(colIndex++);
//			cell.setCellValue("考核依据");
//			cell.setCellStyle(songti11boldcenter);
//			sheet.setColumnWidth(colIndex - 1, 20 * 256);
			cell = row.createCell(colIndex++);
			cell.setCellValue("考核形式");
			cell.setCellStyle(songti12boldcenterwithborder);
			sheet.setColumnWidth(colIndex - 1, 20 * 256);
			cell = row.createCell(colIndex++);
			cell.setCellValue("奖罚情况");
			cell.setCellStyle(songti12boldcenterwithborder);
			sheet.setColumnWidth(colIndex - 1, 20 * 256);
			cell = row.createCell(colIndex++);
			cell.setCellValue("合计");
			cell.setCellStyle(songti12boldcenterwithborder);
			sheet.setColumnWidth(colIndex - 1, 20 * 256);
			// 产生表头2end
			
			// 以下填充数据
			int xh = 1; // 序号
			
			Long lastDeptId = 0L;
			BigDecimal currentTotalScore = null;
			int currentMergedRows = 1;
			BigDecimal lastTotalScore = null;
			int lastMergedRows = 0;
			boolean mergeFlag = false;
			Cell lastMergedCell = null;
			Cell currentMergedCell = null;
			for (Scene result : sceneList) {// 填充数据
				colIndex = 0;
				row = sheet.createRow(rowIndex++);
				row.setHeight((short)(2700));
				cell = row.createCell(colIndex++);
				cell.setCellValue(xh++);
				cell.setCellStyle(songti14centerwithborder);
				cell = row.createCell(colIndex++);
				cell.setCellValue(result.getDept().getDeptName());
				cell.setCellStyle(songti14centerwithborder);
				cell = row.createCell(colIndex++);
				cell.setCellValue(result.getContent1());
				cell.setCellStyle(songti14leftwithborder);
				cell = row.createCell(colIndex++);
				this.writePicToExcel(result.getAttach(), wb, sheet, colIndex - 1, rowIndex - 1); // 图片
				cell.setCellStyle(songti14centerwithborder);
//				cell = row.createCell(colIndex++);
//				cell.setCellValue(result.getContent2());
//				cell.setCellStyle(songti11center);
				cell = row.createCell(colIndex++);
				cell.setCellValue(result.getContent3());
				cell.setCellStyle(songti14centerwithborder);
				cell = row.createCell(colIndex++);
				cell.setCellValue(formatNumber(result.getScore()));
				cell.setCellStyle(songti14centerwithborder);
				Cell totalCell = row.createCell(colIndex++);
				totalCell.setCellValue(formatNumber(result.getScore()));
				totalCell.setCellStyle(songti14centerwithborder);
				
				mergeFlag = false;
				if (result.getDept().getDeptId().equals(lastDeptId)) {
					currentMergedRows++;
					currentTotalScore = currentTotalScore.add(result.getScore());
				} else {
					lastTotalScore = currentTotalScore;
					lastMergedRows = currentMergedRows;
					lastMergedCell = currentMergedCell;
					mergeFlag = true;
					
					currentTotalScore = result.getScore();
					currentMergedRows = 1;
					currentMergedCell = totalCell;
				}
				lastDeptId = result.getDept().getDeptId();
				
				if (mergeFlag && lastMergedCell != null && lastMergedRows > 1) {
					// 总分合计
					lastMergedCell.setCellValue(formatNumber(lastTotalScore));
					region = new CellRangeAddress(rowIndex-1-lastMergedRows, rowIndex-1-1, colIndex-1, colIndex-1);
					sheet.addMergedRegion(region);
				}
			}
			if (currentMergedRows > 1) {
				currentMergedCell.setCellValue(formatNumber(currentTotalScore));
				region = new CellRangeAddress(rowIndex-currentMergedRows, rowIndex-1, colIndex-1, colIndex-1);
				sheet.addMergedRegion(region);
			}
			// 汇总表 end
			
			String filepath = Utils.getExportAbsoluteFile(filename);
			File file = new File(filepath);
			if (file.exists() && file.isFile()) {
				file.delete();
			}
			out = new FileOutputStream(filepath);
			wb.write(out);
			return AjaxResult.success(filename);
		} catch (Exception e) {
			e.printStackTrace();
			return AjaxResult.error("导出Excel失败，请联系网站管理员！");
		} finally {
			IOUtils.closeQuietly(wb);
			IOUtils.closeQuietly(out);
		}
	}
	
	// 写入图片至excel中
	@SuppressWarnings("unused")
	private void writePicToExcel(Attach attach, HSSFWorkbook wb, Sheet sheet, int col, int row) {
		if (attach == null || StringUtils.isBlank(attach.getPath())) {
			return;
		}
		
		String basePath = configService.selectConfigByKey("ATTACH_BASE_PATH");
    	if (StringUtils.isBlank(basePath)) {
    		throw new RuntimeException("ATTACH_BASE_PATH没有配置！");
    	}
    	
    	String filePath = basePath + File.separator + attach.getPath();
		File f = new File(filePath);
		if (!f.exists()) {
			return;
		}
		
		byte[] data;
		try {
			data = IOUtils.toByteArray(new FileInputStream(filePath));
			
			int picId = wb.addPicture(data, Workbook.PICTURE_TYPE_JPEG);
			HSSFPatriarch drawing = (HSSFPatriarch) sheet.createDrawingPatriarch();
			
			HSSFClientAnchor anchor = new HSSFClientAnchor();
//			anchor.setDx1(2);
//			anchor.setDx2(2);
//			anchor.setDy1(2);
//			anchor.setDy2(2);
			anchor.setCol1(col); // Sets the column (0 based) of the first cell.
			anchor.setCol2(col + 1); // Sets the column (0 based) of the Second cell.
			anchor.setRow1(row); // Sets the row (0 based) of the first cell.
			anchor.setRow2(row + 1); // Sets the row (0 based) of the Second cell.
			anchor.setAnchorType(AnchorType.MOVE_AND_RESIZE);

			HSSFPicture pic = drawing.createPicture(anchor, picId);
//			pic.resize(0.99, 0.99);
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException("系统错误");
		} finally {
			data = null;
		}
    }
	
	/**
	@RequestMapping("/submitToCheck")
	@ResponseBody
	public AjaxResult submitToCheck(Scene scene) {
		if (StringUtils.isBlank(scene.getId())) {
			throw new RuntimeException("请求参数id错误！");
		}

		scene = this.sceneService.get(scene);
		if (scene == null) {
			throw new RuntimeException("can not find scene！");
		}

		this.sceneService.submitToCheck(scene);

		return AjaxResult.success("提交审核成功！");
	}
	**/
	
	/**
	@PostMapping("/batchSubmitToCheck")
	@ResponseBody
	public AjaxResult batchSubmitToCheck(String ids, Kh kh) {
		if (StringUtils.isBlank(kh.getPageFlag())) {
			throw new RuntimeException("请求参数pageFlag为空！");
		}

		if (StringUtils.isBlank(ids)) {
			throw new RuntimeException("请求参数ids错误！");
		}
		
		int i = this.khService.batchSubmitToCheck(kh, ids);
		
		return AjaxResult.success("批量提交审核【" + i + "】条记录！");
	}
	**/

	@PostMapping("/submitCheck")
	@ResponseBody
	public AjaxResult submitCheck(Scene scene) {
		String pageFlag = scene.getPageFlag();
		if (StringUtils.isBlank(pageFlag)) {
			throw new RuntimeException("请求参数pageFlag为空！");
		}

		if (StringUtils.isBlank(scene.getId())) {
			throw new RuntimeException("请求参数id错误！");
		}
		
		this.sceneService.submitCheck(scene);

		return AjaxResult.success("审核成功！");
	}
	
	@PostMapping("/batchSubmitCheck")
	@ResponseBody
	public AjaxResult batchSubmitCheck(String ids, Scene scene) {
		if (StringUtils.isBlank(scene.getPageFlag())) {
			throw new RuntimeException("请求参数pageFlag为空！");
		}
		
		if (StringUtils.isBlank(scene.getCheckResult())) {
			throw new RuntimeException("请求参数checkResult为空！");
		}

		if (StringUtils.isBlank(ids)) {
			throw new RuntimeException("请求参数ids错误！");
		}
		
		int i = this.sceneService.batchSubmitCheck(scene, ids);
		
		return AjaxResult.success("批量审核成功【" + i + "】条记录！");
	}

	@RequestMapping("/cancelCheck")
	@ResponseBody
	public AjaxResult cancelCheck(Scene scene) {
		if (scene == null || StringUtils.isBlank(scene.getPageFlag())) {
			throw new RuntimeException("请求参数pageFlag为空！");
		}

		if (StringUtils.isBlank(scene.getId())) {
			throw new RuntimeException("请求参数id错误！");
		}
		
		this.sceneService.cancelCheck(scene);

		return AjaxResult.success("撤销审核成功！");
	}
    
    /**
     * 撤回报表
     * @param id
     * @param mmap
     * @return
     */
    @RequestMapping("/cancelSubmit")
    @ResponseBody
    public AjaxResult cancelSubmit(Scene scene) {
    	scene = this.sceneService.get(scene);
		if (scene == null) {
			throw new RuntimeException("找不到对应的数据！");
		}
		
		if (!Constants.SCENE_STATUS_CHECK10.equals(scene.getStatus())) {
			throw new RuntimeException("当前申请状态不允许当前操作！");
		}
		
		this.sceneService.cancelSubmit(scene);
		
    	return AjaxResult.success("撤回成功！");
    }
    
    /**
    @PostMapping("/batchCancel")
	@ResponseBody
	public AjaxResult batchCancel(String ids, Kh kh) {
		if (StringUtils.isBlank(kh.getPageFlag())) {
			throw new RuntimeException("请求参数pageFlag为空！");
		}
		if (StringUtils.isBlank(ids)) {
			throw new RuntimeException("请求参数ids错误！");
		}
		int i = this.khService.batchCancel(kh, ids);
		
		return AjaxResult.success("批量撤回申请成功【" + i + "】条记录！");
	}
	**/
	
	@RequestMapping("/delete/{id}")
    @ResponseBody
    public AjaxResult delete(@PathVariable("id") String id) {
    	if (StringUtils.isBlank(id)) {
    		throw new RuntimeException("请求参数错误：【id=" + id + "】");
    	}
    	
    	Scene scene = this.sceneService.get(id);
		if (scene == null) {
			throw new RuntimeException("找不到对应的数据！");
		}
		
		this.sceneService.delete(scene);
		
    	return AjaxResult.success("删除成功！");
	}
	
	private List<User> getFgldList() {
		List<User> list = new ArrayList<>();
		List<User> jyz = Utils.jyzList();
		List<User> fgld = Utils.fgldList();
		if (jyz != null) {
			list.addAll(jyz);
		}
		if (fgld != null) {
			list.addAll(fgld);
		}
		return list;
	}
	
	private CellStyle baseStyleWithoutBorder(Workbook wb) {
		CellStyle style = wb.createCellStyle();
		style.setWrapText(true);
		return style;
	}
	private CellStyle baseStyleWithBorder(Workbook wb) {
		CellStyle style = this.baseStyleWithoutBorder(wb);
		style.setWrapText(true);
		style.setBorderLeft(BorderStyle.THIN);
		style.setBorderTop(BorderStyle.THIN);
		style.setBorderRight(BorderStyle.THIN);
		style.setBorderBottom(BorderStyle.THIN);
		return style;
	}
	private CellStyle songti20BoldCenterWithoutBorder(Workbook wb) {
		CellStyle style = this.baseStyleWithoutBorder(wb);
		style.setAlignment(HorizontalAlignment.CENTER);
		style.setVerticalAlignment(VerticalAlignment.CENTER);
		style.setFont(Utils.fontOfSongti20Bold(wb));
		return style;
	}
	private CellStyle songti14BoldLeftWithoutBorder(Workbook wb) {
		CellStyle style = this.baseStyleWithoutBorder(wb);
		style.setAlignment(HorizontalAlignment.LEFT);
		style.setVerticalAlignment(VerticalAlignment.CENTER);
		style.setFont(Utils.fontOfSongti14Bold(wb));
		return style;
	}
	private CellStyle songti12BoldCenterWithBorder(Workbook wb) {
		CellStyle style = this.baseStyleWithBorder(wb);
		style.setAlignment(HorizontalAlignment.CENTER);
		style.setVerticalAlignment(VerticalAlignment.CENTER);
		style.setFont(Utils.fontOfSongti12Bold(wb));
		return style;
	}
	private CellStyle songti14CenterWithBorder(Workbook wb) {
		CellStyle style = this.baseStyleWithBorder(wb);
		style.setAlignment(HorizontalAlignment.CENTER);
		style.setVerticalAlignment(VerticalAlignment.CENTER);
		style.setFont(Utils.fontOfSongti14(wb));
		return style;
	}
	private CellStyle songti14LeftWithBorder(Workbook wb) {
		CellStyle style = this.baseStyleWithBorder(wb);
		style.setAlignment(HorizontalAlignment.LEFT);
		style.setVerticalAlignment(VerticalAlignment.CENTER);
		style.setFont(Utils.fontOfSongti14(wb));
		return style;
	}
	private String formatNumber(BigDecimal input) {
		if (input == null) {
			return "";
		}
		
		return this.formatNumber(input.toString());
	}
	private String formatNumber(String input) {
		if (StringUtils.isBlank(input)) {
			return "";
		}
		
		String v = input;
		while (v.contains(".") && v.endsWith("0")) {
			v = v.substring(0, v.length() - 1);
		}
		if (v.endsWith(".")) {
			v = v.substring(0, v.length() - 1);
		}
		return v;
	}
}